﻿
using System;
using System.IO;

using IronLua.Ast;
using IronLua.Parser;

using NUnit.Framework;

namespace IronLua.Tests.Parser {

	[TestFixture]
	public class ParserTestFixture : AbstractTestFixture {

		public override string Folder {
			get { return "Parser"; }
		}

		[Test]
		public void Hello ()
		{
			RunParserTest ("hello");
		}

		[Test]
		public void BinOps ()
		{
			RunParserTest ("binops");
		}

		[Test]
		public void Assign ()
		{
			RunParserTest ("assign");
		}

		[Test]
		public void For ()
		{
			RunParserTest ("for");
		}

		[Test]
		public void While ()
		{
			RunParserTest ("while");
		}

		[Test]
		public void Repeat ()
		{
			RunParserTest ("repeat");
		}

		[Test]
		public void Call ()
		{
			RunParserTest ("call");
		}

		[Test]
		public void Func ()
		{
			RunParserTest ("func");
		}

		[Test]
		public void If ()
		{
			RunParserTest ("if");
		}

		[Test]
		public void Factorial ()
		{
			RunParserTest ("factorial");
		}

		void RunParserTest (string name)
		{
			var code = File.ReadAllText (GetTestCasePath (name + ".lua"));
			var rt = File.ReadAllText (GetTestCasePath (name + ".rt.lua"));

			Assert.AreEqual (Normalize (rt), Normalize (Parse (code).ToCodeString ()));
		}

		static LuaNode Parse (string chunk)
		{
			return LuaParser.Parse (chunk);
		}
	}
}
